package cn.echo.modules.sys.controller;

import cn.echo.modules.sys.dao.AdminDao;
import cn.echo.modules.sys.entity.Admin;
import cn.echo.modules.sys.utils.SessionFactory;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by Administrator on 2017/5/31.
 */
@Controller
@RequestMapping("xuanshuai")
public class IndexController {

    @RequestMapping(value = "index.html", method = RequestMethod.POST)
    public String qq(Admin admin) {
        SqlSession session = SessionFactory.getSession();
        AdminDao adminDao = session.getMapper(AdminDao.class);
        String username = admin.getUsername();
        String password = admin.getPassword();
        System.out.println("账号:" + username);
        System.out.println("密码:" + password);
        admin.setUsername(username);
        admin.setPassword(password);
        List list=adminDao.selectAdmin1(admin);
        if(list.size()!=0) {
            System.out.println("对象:"+list.get(0));
            return "sys/index";
        }else{
            return "sys/shibai";
        }
    }
    @RequestMapping(value="index.html1",method = RequestMethod.POST)
    public String list(Model model,Admin admin){
        SqlSession session = SessionFactory.getSession();
        AdminDao adminDao = session.getMapper(AdminDao.class);
        List<Admin> list=adminDao.selectAdmin(admin);
        model.addAttribute("list",list);
        return "sys/index";
    }
}